package com.gxa.controller.asset;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.R;
import com.gxa.entity.asset.ConnectRecord;
import com.gxa.entity.asset.Equipment;
import com.gxa.entity.asset.search.ConnectRecordSearchMap;
import com.gxa.service.asset.ConnectRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/10/14 8:32
 **/
@Api(tags = "设备移交--->移交记录")
@RestController
@RequestMapping("/connect-record")
public class ConnectRecordController {
    @Autowired
    private ConnectRecordService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("移交记录列表接口")
    @GetMapping("/list")
    public R queryAll(ConnectRecordSearchMap map){
        PageInfo<ConnectRecord> pageInfo = service.queryByPage(map);
        return ok("successs").put("data",pageInfo).put("department",service.getDepts());
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增移交记录接口")
    @PostMapping("/add")
    public R add(@RequestBody ConnectRecord device){
        boolean save = this.service.save(device);
        if(save){
            return R.ok("添加成功！");
        }
        return error("添加失败");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除移交记录接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        boolean b = service.removeById(id);
        if (b){
            return R.ok("删除成功");
        }
        return error("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询移交记录接口")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Integer id){
        ConnectRecord connectRecord = service.getById(id);
        if(connectRecord != null){
            return R.ok("查询成功！").put("data",connectRecord);
        }
        return error("query error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑移交记录接口")
    @PutMapping("/edit")
    public R edit(@RequestBody ConnectRecord device){
        boolean b = service.updateById(device);
        if(b){
            return R.ok("更新成功！");
        }
        return error("edit error");
    }
}
